package com.baidu.servlet;

import com.baidu.entity.MenuBean;
import com.baidu.service.MenuService;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 创作时间：2019/9/19 8:41
 * 作者：李增强
 */
@WebServlet("/menuServlet")
public class MenuServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MenuService ms = new MenuService();
        List<MenuBean> list= ms.getMenuList();
        String json = JSONArray.fromObject(list).toString();
        req.setAttribute("json", json);
        req.getRequestDispatcher("/WEB-INF/pages/left.jsp").forward(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
